https://www.kaggle.com/zhangjuefei/birds-bones-and-living-habits
Context There are many kinds of birds: pigeons, ducks, ostriches, penguins… Some are good at flying, others can’t fly but run fast. Some swim under water, others wading in shallow pool.
First 6 groups are main and are covered by this dataset.
Apparently, birds belong to different ecological groups have different appearances: flying birds have strong wings and wading birds have long legs. Their living habits are somewhat reflected in their bones’ shapes. As data scientists we may think of examining the underlying relationship between sizes of bones and ecological groups , and recognising birds’ ecological groups by their bones’ shapes.
Content There are 420 birds contained in this dataset. Each bird is represented by 10 measurements (features): — * Length and Diameter of Humerus * Length and Diameter of Ulna * Length and Diameter of Femur * Length and Diameter of Tibiotarsus * Length and Diameter of Tarsometatarsus — All measurements are continuous float numbers (mm) with missing values represented by empty strings. The skeletons of this dataset are collections of Natural History Museum of Los Angeles County. They belong to 21 orders, 153 genera, 245 species.
# Load your packages
library(tidyr)
library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
library(knitr)
library(GGally)
Attaching package: ‘GGally’
The following object is masked from ‘package:dplyr’:
nasa
library(ggplot2)
library(ggridges)
# Load your data and prepare for visualisation
birdDS <- read.csv("bird.csv")
# Load your data and prepare for visualisation
head(birdDS)
# Load your data and prepare for visualisation
colnames(birdDS)
[1] "id" "huml" "humw" "ulnal" "ulnaw" "feml" "femw" "tibl" "tibw" "tarl" "tarw" "type"
colNamesFull <- c("ID", "HumerusLength", "HumerusDiameter", "UlnaLength", "UlnaDiameter",
"FemurLength", "FemurDiameter", "TibiotarusLength", "TibiotarusDiameter",
"TarsometatarusLength", "TarsometatarusDiameter", "EcologicalBirdType")
# Load your data and prepare for visualisation
summary(birdDS)
id huml humw ulnal ulnaw feml
Min. : 0.0 Min. : 9.85 Min. : 1.140 Min. : 14.09 Min. : 1.000 Min. : 11.83
1st Qu.:104.8 1st Qu.: 25.17 1st Qu.: 2.190 1st Qu.: 28.05 1st Qu.: 1.870 1st Qu.: 21.30
Median :209.5 Median : 44.18 Median : 3.500 Median : 43.71 Median : 2.945 Median : 31.13
Mean :209.5 Mean : 64.65 Mean : 4.371 Mean : 69.12 Mean : 3.597 Mean : 36.87
3rd Qu.:314.2 3rd Qu.: 90.31 3rd Qu.: 5.810 3rd Qu.: 97.52 3rd Qu.: 4.770 3rd Qu.: 47.12
Max. :419.0 Max. :420.00 Max. :17.840 Max. :422.00 Max. :12.000 Max. :117.07
NA's :1 NA's :1 NA's :3 NA's :2 NA's :2
femw tibl tibw tarl tarw type
Min. : 0.930 Min. : 5.50 Min. : 0.870 Min. : 7.77 Min. : 0.660 P : 38
1st Qu.: 1.715 1st Qu.: 36.42 1st Qu.: 1.565 1st Qu.: 23.04 1st Qu.: 1.425 R : 50
Median : 2.520 Median : 52.12 Median : 2.490 Median : 31.74 Median : 2.230 SO:128
Mean : 3.221 Mean : 64.66 Mean : 3.182 Mean : 39.23 Mean : 2.930 SW:116
3rd Qu.: 4.135 3rd Qu.: 82.87 3rd Qu.: 4.255 3rd Qu.: 50.25 3rd Qu.: 3.500 T : 23
Max. :11.640 Max. :240.00 Max. :11.030 Max. :175.00 Max. :14.090 W : 65
NA's :1 NA's :2 NA's :1 NA's :1 NA's :1
# Load your data and prepare for visualisation
str(birdDS)
'data.frame': 420 obs. of 12 variables:
$ id : int 0 1 2 3 4 5 6 7 8 9 ...
$ huml : num 80.8 88.9 80 77.7 62.8 ...
$ humw : num 6.68 6.63 6.37 5.7 4.84 ...
$ ulnal: num 72 80.5 69.3 65.8 52.1 ...
$ ulnaw: num 4.88 5.59 5.28 4.77 3.73 3.47 4.5 4.55 6.13 7.05 ...
$ feml : num 41.8 47 43.1 40 34 ...
$ femw : num 3.7 4.3 3.9 3.52 2.72 4.41 3.41 3.78 5.45 7.44 ...
$ tibl : num 5.5 80.2 75.3 69.2 56.3 ...
$ tibw : num 4.03 4.51 4.04 3.4 2.96 2.73 3.56 3.81 5.58 7.31 ...
$ tarl : num 38.7 41.5 38.3 35.8 31.9 ...
$ tarw : num 3.84 4.01 3.34 3.41 3.13 2.83 3.64 3.81 4.37 6.34 ...
$ type : Factor w/ 6 levels "P","R","SO","SW",..: 4 4 4 4 4 4 4 4 4 4 ...
# Load your data and prepare for visualisation
head(birdDS)
# Check the species ID
unique(birdDS$type)
[1] SW W T R P SO
Levels: P R SO SW T W
# Determining the mean values
#meanValueByType <- aggregate(surveys_combined_year$weight ~ species_id,
# surveys_combined_year, mean, na.action = na.omit)
# Checking the output
#average_by_species_year
# SW - Swimming Birds
SWbirds <- subset(birdDS, birdDS$type == "SW") # SW - Swimming Birds
Wbirds <- subset(birdDS, birdDS$type == "W") # W - Wading Birds
Tbirds <- subset(birdDS, birdDS$type == "T") # T - Terrestrial Birds
Rbirds <- subset(birdDS, birdDS$type == "R") # R - Raptors
Pbirds <- subset(birdDS, birdDS$type == "P") # P - Scansorial Birds
SObirds <- subset(birdDS, birdDS$type == "SO") # SO - Singing Birds
summary(SWbirds)
id huml humw ulnal ulnaw feml
Min. : 0.00 Min. : 22.63 Min. : 1.630 Min. : 20.75 Min. : 1.510 Min. : 12.21
1st Qu.: 28.75 1st Qu.: 68.41 1st Qu.: 4.062 1st Qu.: 65.69 1st Qu.: 3.538 1st Qu.: 29.97
Median : 57.50 Median :100.06 Median : 5.735 Median : 96.94 Median : 4.685 Median : 39.33
Mean : 57.50 Mean :110.25 Mean : 6.424 Mean :111.76 Mean : 5.222 Mean : 42.17
3rd Qu.: 86.25 3rd Qu.:143.50 3rd Qu.: 7.878 3rd Qu.:133.75 3rd Qu.: 6.540 3rd Qu.: 51.02
Max. :115.00 Max. :420.00 Max. :17.840 Max. :422.00 Max. :11.720 Max. :110.54
femw tibl tibw tarl tarw type
Min. :0.970 Min. : 5.50 Min. : 1.010 Min. : 18.42 Min. : 0.830 P : 0
1st Qu.:2.572 1st Qu.: 57.59 1st Qu.: 2.712 1st Qu.: 30.12 1st Qu.: 2.245 R : 0
Median :3.660 Median : 75.28 Median : 4.035 Median : 39.70 Median : 3.225 SO: 0
Mean :4.276 Mean : 85.32 Mean : 4.514 Mean : 45.16 Mean : 4.150 SW:116
3rd Qu.:5.810 3rd Qu.:106.03 3rd Qu.: 6.378 3rd Qu.: 56.14 3rd Qu.: 5.630 T : 0
Max. :9.990 Max. :237.00 Max. :11.030 Max. :128.35 Max. :14.090 W : 0
summary(Wbirds) # Two NA
id huml humw ulnal ulnaw feml
Min. :116 Min. : 22.39 Min. : 1.530 Min. : 24.16 Min. : 1.290 Min. : 15.71
1st Qu.:132 1st Qu.: 38.79 1st Qu.: 2.810 1st Qu.: 36.33 1st Qu.: 2.640 1st Qu.: 26.55
Median :148 Median : 70.93 Median : 4.340 Median : 75.44 Median : 3.840 Median : 38.41
Mean :148 Mean : 73.13 Mean : 4.607 Mean : 78.10 Mean : 4.103 Mean : 40.12
3rd Qu.:164 3rd Qu.: 88.16 3rd Qu.: 5.630 3rd Qu.: 99.31 3rd Qu.: 5.060 3rd Qu.: 48.23
Max. :180 Max. :190.00 Max. :11.920 Max. :225.00 Max. :12.000 Max. :101.75
NA's :1
femw tibl tibw tarl tarw type
Min. :1.140 Min. : 30.31 Min. :0.990 Min. : 15.80 Min. :0.83 P : 0
1st Qu.:2.075 1st Qu.: 46.24 1st Qu.:2.060 1st Qu.: 24.64 1st Qu.:1.71 R : 0
Median :3.020 Median : 70.39 Median :2.990 Median : 37.17 Median :2.53 SO: 0
Mean :3.119 Mean : 76.15 Mean :3.179 Mean : 47.54 Mean :2.76 SW: 0
3rd Qu.:4.043 3rd Qu.: 89.93 3rd Qu.:4.090 3rd Qu.: 60.81 3rd Qu.:3.57 T : 0
Max. :7.750 Max. :240.00 Max. :7.710 Max. :175.00 Max. :7.00 W :65
NA's :1
summary(Tbirds)
id huml humw ulnal ulnaw feml
Min. :181.0 Min. : 20.25 Min. : 2.350 Min. : 25.14 Min. :1.760 Min. : 20.17
1st Qu.:186.5 1st Qu.: 32.06 1st Qu.: 3.290 1st Qu.: 28.64 1st Qu.:2.430 1st Qu.: 36.23
Median :192.0 Median : 34.24 Median : 3.600 Median : 35.24 Median :2.910 Median : 39.38
Mean :192.0 Mean : 45.70 Mean : 4.786 Mean : 45.62 Mean :3.472 Mean : 46.28
3rd Qu.:197.5 3rd Qu.: 44.27 3rd Qu.: 4.715 3rd Qu.: 51.58 3rd Qu.:3.765 3rd Qu.: 41.72
Max. :203.0 Max. :127.00 Max. :13.790 Max. :123.27 Max. :9.420 Max. :117.07
femw tibl tibw tarl tarw type
Min. : 1.370 Min. : 27.67 Min. : 1.410 Min. : 15.68 Min. :1.550 P : 0
1st Qu.: 2.645 1st Qu.: 49.03 1st Qu.: 2.380 1st Qu.: 26.78 1st Qu.:2.340 R : 0
Median : 2.870 Median : 53.77 Median : 2.710 Median : 31.00 Median :2.490 SO: 0
Mean : 3.820 Mean : 66.09 Mean : 3.452 Mean : 40.09 Mean :3.184 SW: 0
3rd Qu.: 3.365 3rd Qu.: 56.44 3rd Qu.: 3.155 3rd Qu.: 34.82 3rd Qu.:2.945 T :23
Max. :11.640 Max. :189.00 Max. :10.030 Max. :134.00 Max. :8.190 W : 0
summary(Rbirds) # Four NA
id huml humw ulnal ulnaw feml
Min. :204.0 Min. : 33.12 Min. : 2.400 Min. : 39.85 Min. :1.800 Min. :27.46
1st Qu.:216.2 1st Qu.: 57.50 1st Qu.: 4.395 1st Qu.: 67.15 1st Qu.:3.540 1st Qu.:48.84
Median :228.5 Median : 89.88 Median : 6.125 Median :102.65 Median :4.800 Median :62.31
Mean :228.5 Mean : 86.93 Mean : 6.066 Mean :100.34 Mean :4.813 Mean :62.02
3rd Qu.:240.8 3rd Qu.:115.03 3rd Qu.: 7.550 3rd Qu.:129.39 3rd Qu.:6.190 3rd Qu.:76.16
Max. :253.0 Max. :145.00 Max. :10.370 Max. :188.00 Max. :7.920 Max. :94.79
NA's :1 NA's :1
femw tibl tibw tarl tarw type
Min. :2.190 Min. : 38.99 Min. :2.150 Min. :19.10 Min. :2.220 P : 0
1st Qu.:3.783 1st Qu.: 66.58 1st Qu.:3.478 1st Qu.:46.81 1st Qu.:3.150 R :50
Median :5.060 Median : 96.36 Median :4.935 Median :60.19 Median :4.950 SO: 0
Mean :5.267 Mean : 89.88 Mean :4.949 Mean :59.17 Mean :5.074 SW: 0
3rd Qu.:6.670 3rd Qu.:113.21 3rd Qu.:6.115 3rd Qu.:73.29 3rd Qu.:6.800 T : 0
Max. :8.920 Max. :126.54 Max. :7.900 Max. :99.72 Max. :9.640 W : 0
NA's :1 NA's :1
summary(Pbirds)
id huml humw ulnal ulnaw feml
Min. :254.0 Min. : 9.85 Min. :1.730 Min. :14.73 Min. :1.410 Min. :16.27
1st Qu.:263.2 1st Qu.:28.70 1st Qu.:2.660 1st Qu.:31.96 1st Qu.:2.067 1st Qu.:20.64
Median :272.5 Median :33.80 Median :2.930 Median :38.55 Median :2.415 Median :25.40
Mean :272.5 Mean :34.42 Mean :3.039 Mean :39.18 Mean :2.476 Mean :28.22
3rd Qu.:281.8 3rd Qu.:42.30 3rd Qu.:3.493 3rd Qu.:47.30 3rd Qu.:2.900 3rd Qu.:31.86
Max. :291.0 Max. :49.12 Max. :4.640 Max. :60.95 Max. :3.520 Max. :54.67
femw tibl tibw tarl tarw type
Min. :1.210 Min. :20.89 Min. :1.050 Min. : 7.77 Min. :1.160 P :38
1st Qu.:1.980 1st Qu.:31.97 1st Qu.:1.633 1st Qu.:15.82 1st Qu.:1.532 R : 0
Median :2.135 Median :36.65 Median :1.885 Median :21.89 Median :1.740 SO: 0
Mean :2.308 Mean :41.88 Mean :2.096 Mean :25.79 Mean :1.903 SW: 0
3rd Qu.:2.505 3rd Qu.:49.23 3rd Qu.:2.283 3rd Qu.:30.54 3rd Qu.:2.058 T : 0
Max. :4.250 Max. :85.88 Max. :4.120 Max. :63.91 Max. :3.600 W : 0
summary(SObirds) # Nine NA
id huml humw ulnal ulnaw feml
Min. :292.0 Min. :12.69 Min. :1.14 Min. :14.09 Min. :1.000 Min. :11.83
1st Qu.:323.8 1st Qu.:18.68 1st Qu.:1.66 1st Qu.:21.99 1st Qu.:1.410 1st Qu.:17.23
Median :355.5 Median :21.53 Median :1.93 Median :25.64 Median :1.710 Median :20.67
Mean :355.5 Mean :22.36 Mean :2.03 Mean :26.40 Mean :1.744 Mean :21.38
3rd Qu.:387.2 3rd Qu.:25.30 3rd Qu.:2.32 3rd Qu.:29.23 3rd Qu.:1.955 3rd Qu.:24.02
Max. :419.0 Max. :48.20 Max. :4.08 Max. :61.94 Max. :3.750 Max. :40.11
NA's :1 NA's :1 NA's :2 NA's :1 NA's :1
femw tibl tibw tarl tarw type
Min. :0.93 Min. :22.13 Min. :0.870 Min. :15.19 Min. :0.660 P : 0
1st Qu.:1.28 1st Qu.:28.70 1st Qu.:1.220 1st Qu.:19.84 1st Qu.:1.048 R : 0
Median :1.64 Median :35.48 Median :1.430 Median :24.31 Median :1.265 SO:128
Mean :1.68 Mean :36.33 Mean :1.549 Mean :25.84 Mean :1.349 SW: 0
3rd Qu.:1.91 3rd Qu.:40.73 3rd Qu.:1.780 3rd Qu.:29.65 3rd Qu.:1.603 T : 0
Max. :3.51 Max. :64.97 Max. :3.210 Max. :48.35 Max. :2.570 W : 0
NA's :2 NA's :1
# Filling NA - Rbirds
Wbirds$feml[is.na(Wbirds$feml)] <- mean(Wbirds$feml, na.rm = TRUE)
Wbirds$femw[is.na(Wbirds$femw)] <- mean(Wbirds$femw, na.rm = TRUE)
# Filling NA - Rbirds
Rbirds$ulnal[is.na(Rbirds$ulnal)] <- mean(Rbirds$ulnal, na.rm = TRUE)
Rbirds$ulnaw[is.na(Rbirds$ulnaw)] <- mean(Rbirds$ulnaw, na.rm = TRUE)
Rbirds$tarl[is.na(Rbirds$tarl)] <- mean(Rbirds$tarl, na.rm = TRUE)
Rbirds$tarw[is.na(Rbirds$tarw)] <- mean(Rbirds$tarw, na.rm = TRUE)
# Filling NA - SObirds
SObirds$huml[is.na(SObirds$huml)] <- mean(SObirds$huml, na.rm = TRUE)
SObirds$humw[is.na(SObirds$humw)] <- mean(SObirds$humw, na.rm = TRUE)
SObirds$ulnal[is.na(SObirds$ulnal)] <- mean(SObirds$ulnal, na.rm = TRUE)
SObirds$ulnaw[is.na(SObirds$ulnaw)] <- mean(SObirds$ulnaw, na.rm = TRUE)
SObirds$feml[is.na(SObirds$feml)] <- mean(SObirds$feml, na.rm = TRUE)
SObirds$tibl[is.na(SObirds$tibl)] <- mean(SObirds$tibl, na.rm = TRUE)
SObirds$tibw[is.na(SObirds$tibw)] <- mean(SObirds$tibw, na.rm = TRUE)
birdDS_clean <- rbind(SWbirds, Wbirds, Tbirds, Rbirds, Pbirds, SObirds)
summary(birdDS_clean)
id huml humw ulnal ulnaw feml
Min. : 0.0 Min. : 9.85 Min. : 1.140 Min. : 14.09 Min. : 1.000 Min. : 11.83
1st Qu.:104.8 1st Qu.: 25.04 1st Qu.: 2.188 1st Qu.: 28.00 1st Qu.: 1.867 1st Qu.: 21.33
Median :209.5 Median : 44.08 Median : 3.495 Median : 43.51 Median : 2.945 Median : 31.13
Mean :209.5 Mean : 64.55 Mean : 4.365 Mean : 68.99 Mean : 3.596 Mean : 36.84
3rd Qu.:314.2 3rd Qu.: 90.22 3rd Qu.: 5.805 3rd Qu.: 97.56 3rd Qu.: 4.772 3rd Qu.: 47.10
Max. :419.0 Max. :420.00 Max. :17.840 Max. :422.00 Max. :12.000 Max. :117.07
femw tibl tibw tarl tarw type
Min. : 0.930 Min. : 5.50 Min. : 0.870 Min. : 7.77 Min. : 0.660 P : 38
1st Qu.: 1.718 1st Qu.: 36.34 1st Qu.: 1.560 1st Qu.: 23.04 1st Qu.: 1.427 R : 50
Median : 2.525 Median : 51.94 Median : 2.490 Median : 31.81 Median : 2.235 SO:128
Mean : 3.221 Mean : 64.53 Mean : 3.178 Mean : 39.28 Mean : 2.935 SW:116
3rd Qu.: 4.122 3rd Qu.: 82.87 3rd Qu.: 4.253 3rd Qu.: 50.46 3rd Qu.: 3.522 T : 23
Max. :11.640 Max. :240.00 Max. :11.030 Max. :175.00 Max. :14.090 W : 65
ggplot(data = birdDS_clean, aes(x = type, y = huml)) + geom_boxplot()
ggplot(data = birdDS_clean, aes(x = type, y = humw)) + geom_boxplot()
ggplot(data = birdDS_clean, aes(x = type, y = ulnal)) + geom_boxplot()
ggplot(data = birdDS_clean, aes(x = type, y = ulnaw)) + geom_boxplot()
ggplot(data = birdDS_clean, aes(x = type, y = feml)) + geom_boxplot()
ggplot(data = birdDS_clean, aes(x = type, y = femw)) + geom_boxplot()
colnames(birdDS_clean)
[1] "id" "huml" "humw" "ulnal" "ulnaw" "feml" "femw" "tibl" "tibw" "tarl" "tarw" "type"
allMeasurements <- c("huml", "humw", "ulnal", "ulnaw", "feml", "femw", "tibl", "tibw", "tarl", "tarw")
lengthMeasurements <- c("huml", "ulnal", "feml", "tibl", "tarl")
widthMeasurements <- c("humw", "ulnaw", "femw", "tibw", "tarw")
# Visualise Your Data
scatter_matrix <- ggpairs(data = birdDS_clean,
columns = allMeasurements,
mapping = aes(colour = type),
diag = list(continuous = wrap("densityDiag", alpha=I(0.1)), mapping = ggplot2::aes(fill=type)),
upper = list(continuous = wrap("density", alpha = I(0.5)), combo = "box"),
lower = list(continuous = wrap("points", alpha = I(0.4), size = 0.1)))
scatter_matrix_adjusted <- scatter_matrix + theme(panel.spacing=grid::unit(0,"lines"),
axis.text = element_text(size = rel(0.5)),
strip.text = element_text(face = "bold", size=7),
strip.text.x = element_text(margin = margin(.1, 0, .1, 0, "cm")),
strip.text.y = element_text(margin = margin(0, .1, 0, .1, "cm")))
scatter_matrix_adjusted + theme(panel.border = element_rect(fill = NA, colour = "grey30", size = 0.2))
plot: [1,1] [=-------------------------------------------------------------------------] 1% est: 0s
plot: [1,2] [=-------------------------------------------------------------------------] 2% est:20s
plot: [1,3] [==------------------------------------------------------------------------] 3% est:37s
plot: [1,4] [===-----------------------------------------------------------------------] 4% est:41s
plot: [1,5] [====----------------------------------------------------------------------] 5% est:40s
plot: [1,6] [====----------------------------------------------------------------------] 6% est:39s
plot: [1,7] [=====---------------------------------------------------------------------] 7% est:39s
plot: [1,8] [======--------------------------------------------------------------------] 8% est:39s
plot: [1,9] [=======-------------------------------------------------------------------] 9% est:38s
plot: [1,10] [=======------------------------------------------------------------------] 10% est:38s
plot: [2,1] [========------------------------------------------------------------------] 11% est:38s
plot: [2,2] [=========-----------------------------------------------------------------] 12% est:35s
plot: [2,3] [==========----------------------------------------------------------------] 13% est:33s
plot: [2,4] [==========----------------------------------------------------------------] 14% est:33s
plot: [2,5] [===========---------------------------------------------------------------] 15% est:33s
plot: [2,6] [============--------------------------------------------------------------] 16% est:33s
plot: [2,7] [=============-------------------------------------------------------------] 17% est:33s
plot: [2,8] [=============-------------------------------------------------------------] 18% est:32s
plot: [2,9] [==============------------------------------------------------------------] 19% est:33s
plot: [2,10] [===============----------------------------------------------------------] 20% est:32s
plot: [3,1] [================----------------------------------------------------------] 21% est:32s
plot: [3,2] [================----------------------------------------------------------] 22% est:30s
plot: [3,3] [=================---------------------------------------------------------] 23% est:29s
plot: [3,4] [==================--------------------------------------------------------] 24% est:28s
plot: [3,5] [==================--------------------------------------------------------] 25% est:28s
plot: [3,6] [===================-------------------------------------------------------] 26% est:28s
plot: [3,7] [====================------------------------------------------------------] 27% est:28s
plot: [3,8] [=====================-----------------------------------------------------] 28% est:27s
plot: [3,9] [=====================-----------------------------------------------------] 29% est:27s
plot: [3,10] [======================---------------------------------------------------] 30% est:27s
plot: [4,1] [=======================---------------------------------------------------] 31% est:27s
plot: [4,2] [========================--------------------------------------------------] 32% est:26s
plot: [4,3] [========================--------------------------------------------------] 33% est:25s
plot: [4,4] [=========================-------------------------------------------------] 34% est:24s
plot: [4,5] [==========================------------------------------------------------] 35% est:23s
plot: [4,6] [===========================-----------------------------------------------] 36% est:23s
plot: [4,7] [===========================-----------------------------------------------] 37% est:23s
plot: [4,8] [============================----------------------------------------------] 38% est:23s
plot: [4,9] [=============================---------------------------------------------] 39% est:22s
plot: [4,10] [=============================--------------------------------------------] 40% est:22s
plot: [5,1] [==============================--------------------------------------------] 41% est:22s
plot: [5,2] [===============================-------------------------------------------] 42% est:21s
plot: [5,3] [================================------------------------------------------] 43% est:20s
plot: [5,4] [=================================-----------------------------------------] 44% est:20s
plot: [5,5] [=================================-----------------------------------------] 45% est:19s
plot: [5,6] [==================================----------------------------------------] 46% est:19s
plot: [5,7] [===================================---------------------------------------] 47% est:18s
plot: [5,8] [====================================--------------------------------------] 48% est:18s
plot: [5,9] [====================================--------------------------------------] 49% est:18s
plot: [5,10] [====================================-------------------------------------] 50% est:18s
plot: [6,1] [======================================------------------------------------] 51% est:17s
plot: [6,2] [======================================------------------------------------] 52% est:17s
plot: [6,3] [=======================================-----------------------------------] 53% est:16s
plot: [6,4] [========================================----------------------------------] 54% est:16s
plot: [6,5] [=========================================---------------------------------] 55% est:15s
plot: [6,6] [=========================================---------------------------------] 56% est:15s
plot: [6,7] [==========================================--------------------------------] 57% est:14s
plot: [6,8] [===========================================-------------------------------] 58% est:14s
plot: [6,9] [============================================------------------------------] 59% est:14s
plot: [6,10] [============================================-----------------------------] 60% est:14s
plot: [7,1] [=============================================-----------------------------] 61% est:13s
plot: [7,2] [==============================================----------------------------] 62% est:13s
plot: [7,3] [===============================================---------------------------] 63% est:12s
plot: [7,4] [===============================================---------------------------] 64% est:12s
plot: [7,5] [================================================--------------------------] 65% est:11s
plot: [7,6] [=================================================-------------------------] 66% est:11s
plot: [7,7] [==================================================------------------------] 67% est:11s
plot: [7,8] [==================================================------------------------] 68% est:10s
plot: [7,9] [===================================================-----------------------] 69% est:10s
plot: [7,10] [===================================================----------------------] 70% est:10s
plot: [8,1] [=====================================================---------------------] 71% est: 9s
plot: [8,2] [=====================================================---------------------] 72% est: 9s
plot: [8,3] [======================================================--------------------] 73% est: 9s
plot: [8,4] [=======================================================-------------------] 74% est: 8s
plot: [8,5] [========================================================------------------] 75% est: 8s
plot: [8,6] [========================================================------------------] 76% est: 7s
plot: [8,7] [=========================================================-----------------] 77% est: 7s
plot: [8,8] [==========================================================----------------] 78% est: 7s
plot: [8,9] [==========================================================----------------] 79% est: 6s
plot: [8,10] [==========================================================---------------] 80% est: 6s
plot: [9,1] [============================================================--------------] 81% est: 6s
plot: [9,2] [=============================================================-------------] 82% est: 5s
plot: [9,3] [=============================================================-------------] 83% est: 5s
plot: [9,4] [==============================================================------------] 84% est: 5s
plot: [9,5] [===============================================================-----------] 85% est: 4s
plot: [9,6] [================================================================----------] 86% est: 4s
plot: [9,7] [================================================================----------] 87% est: 4s
plot: [9,8] [=================================================================---------] 88% est: 4s
plot: [9,9] [==================================================================--------] 89% est: 3s
plot: [9,10] [==================================================================-------] 90% est: 3s
plot: [10,1] [==================================================================-------] 91% est: 3s
plot: [10,2] [===================================================================------] 92% est: 2s
plot: [10,3] [====================================================================-----] 93% est: 2s
plot: [10,4] [=====================================================================----] 94% est: 2s
plot: [10,5] [=====================================================================----] 95% est: 1s
plot: [10,6] [======================================================================---] 96% est: 1s
plot: [10,7] [=======================================================================--] 97% est: 1s
plot: [10,8] [========================================================================-] 98% est: 1s
plot: [10,9] [========================================================================-] 99% est: 0s
plot: [10,10] [========================================================================]100% est: 0s
# Visualise Your Data
scatter_matrix_length <- ggpairs(data = birdDS_clean,
columns = lengthMeasurements,
mapping = aes(colour = type),
diag = list(continuous = wrap("densityDiag", alpha=I(0.1)), mapping = ggplot2::aes(fill=type)),
upper = list(continuous = wrap("density", alpha = I(0.5)), combo = "box"),
lower = list(continuous = wrap("points", alpha = I(0.4), size = 0.1)))
scatter_matrix_length_adjusted <- scatter_matrix_length + theme(panel.spacing=grid::unit(0,"lines"),
axis.text = element_text(size = rel(0.5)),
strip.text = element_text(face = "bold", size=7),
strip.text.x = element_text(margin = margin(.1, 0, .1, 0, "cm")),
strip.text.y = element_text(margin = margin(0, .1, 0, .1, "cm")))
scatter_matrix_length_adjusted + theme(panel.border = element_rect(fill = NA, colour = "grey30", size = 0.2))
plot: [1,1] [===-----------------------------------------------------------------------] 4% est: 0s
plot: [1,2] [======--------------------------------------------------------------------] 8% est: 2s
plot: [1,3] [=========-----------------------------------------------------------------] 12% est: 5s
plot: [1,4] [============--------------------------------------------------------------] 16% est: 6s
plot: [1,5] [===============-----------------------------------------------------------] 20% est: 6s
plot: [2,1] [==================--------------------------------------------------------] 24% est: 6s
plot: [2,2] [=====================-----------------------------------------------------] 28% est: 5s
plot: [2,3] [========================--------------------------------------------------] 32% est: 5s
plot: [2,4] [===========================-----------------------------------------------] 36% est: 5s
plot: [2,5] [==============================--------------------------------------------] 40% est: 5s
plot: [3,1] [=================================-----------------------------------------] 44% est: 4s
plot: [3,2] [====================================--------------------------------------] 48% est: 4s
plot: [3,3] [======================================------------------------------------] 52% est: 3s
plot: [3,4] [=========================================---------------------------------] 56% est: 3s
plot: [3,5] [============================================------------------------------] 60% est: 3s
plot: [4,1] [===============================================---------------------------] 64% est: 3s
plot: [4,2] [==================================================------------------------] 68% est: 2s
plot: [4,3] [=====================================================---------------------] 72% est: 2s
plot: [4,4] [========================================================------------------] 76% est: 2s
plot: [4,5] [===========================================================---------------] 80% est: 1s
plot: [5,1] [==============================================================------------] 84% est: 1s
plot: [5,2] [=================================================================---------] 88% est: 1s
plot: [5,3] [====================================================================------] 92% est: 1s
plot: [5,4] [=======================================================================---] 96% est: 0s
plot: [5,5] [==========================================================================]100% est: 0s
# Visualise Your Data
scatter_matrix_width <- ggpairs(data = birdDS_clean,
columns = widthMeasurements,
mapping = aes(colour = type),
diag = list(continuous = wrap("densityDiag", alpha=I(0.1)), mapping = ggplot2::aes(fill=type)),
upper = list(continuous = wrap("density", alpha = I(0.5)), combo = "box"),
lower = list(continuous = wrap("points", alpha = I(0.4), size = 0.1)))
scatter_matrix_width_adjusted <- scatter_matrix_width + theme(panel.spacing=grid::unit(0,"lines"),
axis.text = element_text(size = rel(0.5)),
strip.text = element_text(face = "bold", size=7),
strip.text.x = element_text(margin = margin(.1, 0, .1, 0, "cm")),
strip.text.y = element_text(margin = margin(0, .1, 0, .1, "cm")))
scatter_matrix_width_adjusted + theme(panel.border = element_rect(fill = NA, colour = "grey30", size = 0.2))
plot: [1,1] [===-----------------------------------------------------------------------] 4% est: 0s
plot: [1,2] [======--------------------------------------------------------------------] 8% est: 2s
plot: [1,3] [=========-----------------------------------------------------------------] 12% est: 5s
plot: [1,4] [============--------------------------------------------------------------] 16% est: 6s
plot: [1,5] [===============-----------------------------------------------------------] 20% est: 6s
plot: [2,1] [==================--------------------------------------------------------] 24% est: 6s
plot: [2,2] [=====================-----------------------------------------------------] 28% est: 5s
plot: [2,3] [========================--------------------------------------------------] 32% est: 5s
plot: [2,4] [===========================-----------------------------------------------] 36% est: 5s
plot: [2,5] [==============================--------------------------------------------] 40% est: 5s
plot: [3,1] [=================================-----------------------------------------] 44% est: 5s
plot: [3,2] [====================================--------------------------------------] 48% est: 4s
plot: [3,3] [======================================------------------------------------] 52% est: 4s
plot: [3,4] [=========================================---------------------------------] 56% est: 3s
plot: [3,5] [============================================------------------------------] 60% est: 3s
plot: [4,1] [===============================================---------------------------] 64% est: 3s
plot: [4,2] [==================================================------------------------] 68% est: 2s
plot: [4,3] [=====================================================---------------------] 72% est: 2s
plot: [4,4] [========================================================------------------] 76% est: 2s
plot: [4,5] [===========================================================---------------] 80% est: 1s
plot: [5,1] [==============================================================------------] 84% est: 1s
plot: [5,2] [=================================================================---------] 88% est: 1s
plot: [5,3] [====================================================================------] 92% est: 1s
plot: [5,4] [=======================================================================---] 96% est: 0s
plot: [5,5] [==========================================================================]100% est: 0s
# Did not work
test_reorder <- birdDS_clean[,c(12,2,3,4,5,6,7,8,9,10,11,1)]
# Did not work
test <- birdDS_clean %>% gather("huml", "humw", "ulnal", "ulnaw", "feml", "femw", "tibl", "tibw", "tarl", "tarw",
key = "id", value = "measurement")
#dim(SWbirds) # L = 116 *
#dim(Wbirds) # L = 65
#dim(Tbirds)
#dim(Rbirds)
#dim(Pbirds)
#dim(SObirds)
SWbirdsLong <- SWbirds %>% gather("huml", "humw", "ulnal", "ulnaw", "feml", "femw", "tibl", "tibw", "tarl", "tarw",
key = "type", value = "measurement")
SWbirdsLong$id <- 'SW'
WbirdsLong <- Wbirds %>% gather("huml", "humw", "ulnal", "ulnaw", "feml", "femw", "tibl", "tibw", "tarl", "tarw",
key = "type", value = "measurement")
WbirdsLong$id <- 'W'
TbirdsLong <- Tbirds %>% gather("huml", "humw", "ulnal", "ulnaw", "feml", "femw", "tibl", "tibw", "tarl", "tarw",
key = "type", value = "measurement")
TbirdsLong$id <- 'T'
RbirdsLong <- Rbirds %>% gather("huml", "humw", "ulnal", "ulnaw", "feml", "femw", "tibl", "tibw", "tarl", "tarw",
key = "type", value = "measurement")
RbirdsLong$id <- 'R'
PbirdsLong <- Pbirds %>% gather("huml", "humw", "ulnal", "ulnaw", "feml", "femw", "tibl", "tibw", "tarl", "tarw",
key = "type", value = "measurement")
PbirdsLong$id <- 'P'
SObirdsLong <- SObirds %>% gather("huml", "humw", "ulnal", "ulnaw", "feml", "femw", "tibl", "tibw", "tarl", "tarw",
key = "type", value = "measurement")
SObirdsLong$id <- 'SO'
birdDS_Long <- rbind(SWbirdsLong, WbirdsLong, TbirdsLong, RbirdsLong, PbirdsLong, SObirdsLong)
summary(birdDS_Long)
id type measurement
Length:4200 Length:4200 Min. : 0.66
Class :character Class :character 1st Qu.: 2.67
Mode :character Mode :character Median : 12.47
Mean : 29.15
3rd Qu.: 38.50
Max. :422.00
colnames(birdDS_Long) <- c("birdType", "bone", "measurement")
ggNew <- ggplot(data = birdDS_Long, aes(x=birdDS_Long$measurement, y = bone, fill = birdType))
ggNew + geom_density_ridges(aes(x = bone),
alpha = .8, color = "white") +
theme_ridges(grid = FALSE)
ggNew <- ggplot(data = birdDS_Long, aes(x=birdDS_Long$measurement, y = birdType, fill = bone))
ggNew + geom_density_ridges(aes(x = bone),
alpha = .8, color = "white") +
theme_ridges(grid = FALSE)
ggNew <- ggplot(data = birdDS_Long, aes(x=birdDS_Long$measurement, y = birdType, fill = bone))
ggNew + geom_density_ridges(aes(x = measurement), alpha = .8, color = "white") +
theme_ridges(grid = FALSE)
ggNew <- ggplot(data = birdDS_Long, aes(x=birdDS_Long$measurement, y = bone, fill = birdType))
ggNew + geom_density_ridges(aes(x = measurement), alpha = .8, color = "white") +
theme_ridges(grid = FALSE)
ggplot(data = birdDS_Long, aes(x=birdDS_Long$measurement, y = bone, fill = birdType)) +
geom_density_ridges2(scale = 1) +
theme_minimal(base_size = 14) + theme(axis.text.y = element_text(vjust = 0)) +
scale_x_continuous(expand = c(0.01, 0)) +
coord_cartesian(xlim = c(0, 200)) +
scale_y_discrete(expand = c(0.01, 0))
ggplot(data = birdDS_Long, aes(x=birdDS_Long$measurement, y = bone, fill = birdType)) +
geom_density_ridges2(scale = 1) +
theme_minimal(base_size = 14) + theme(axis.text.y = element_text(vjust = 0)) +
scale_x_continuous(expand = c(0.01, 0)) +
coord_cartesian(xlim = c(0, 200)) +
scale_y_discrete(expand = c(0.01, 0)) +
facet_grid(.~birdType)
ggplot(data = birdDS_Long, aes(x=birdDS_Long$measurement, y = birdType, fill = bone)) +
geom_density_ridges2(scale = 1) +
theme_minimal(base_size = 14) + theme(axis.text.y = element_text(vjust = 0)) +
scale_x_continuous(expand = c(0.01, 0)) +
coord_cartesian(xlim = c(0, 200)) +
scale_y_discrete(expand = c(0.01, 0)) +
facet_grid(.~bone)
http://davemcg.github.io/post/let-s-plot-5-ridgeline-density-plots/ https://feedyeti.com/hashtag.php?q=ggridges https://stackoverflow.com/questions/46012951/temperature-plot-error-in-funxi-object-y-not-found http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/ # scale_fill_brewer(palette=“Spectral”) http://ggplot2.tidyverse.org/reference/scale_brewer.html http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf http://clayford.github.io/dwir/dwr_05_combine_merge_rehsape_data.html https://twitter.com/@eatonjw https://stackoverflow.com/questions/46012951/temperature-plot-error-in-funxi-object-y-not-found https://feedyeti.com/hashtag.php?q=ggjoy https://homepage.divms.uiowa.edu/~luke/classes/STAT4580/boxetc.html https://zhuanlan.zhihu.com/p/32115772
ggplot(data = birdDS_Long, aes(x=birdDS_Long$measurement, y = birdType, fill = bone)) +
geom_density_ridges(alpha=0.6) +
coord_cartesian(xlim = c(0, 200)) +
theme_ridges() + scale_fill_brewer(palette = 'Set1')
# Need to add two BOOLEAN columns
# OR
# Length and Width in one column... (this!)
birdDS_Long$measurementType <- sapply(strsplit(as.character(birdDS_Long$bone), ""), tail, 1)
birdDS_Long$boneAlone = substr(birdDS_Long$bone,1,nchar(birdDS_Long$bone)-1)
(aes(y = Drug, x=log2(Area), group=Well.names, fill=DMSO))
* x -> log2(Area)
* y -> Drug
* group -> Well.names
* fill -> DMSO
ggplot(data = birdDS_Long, aes(x=birdDS_Long$measurement, y = birdType, fill = measurementType)) +
geom_density_ridges2(scale = 1) +
theme_minimal(base_size = 14) + theme(axis.text.y = element_text(vjust = 0)) +
scale_x_continuous(expand = c(0.01, 0)) +
coord_cartesian(xlim = c(0, 200)) +
scale_y_discrete(expand = c(0.01, 0)) +
facet_grid(.~boneAlone)
ggplot(data = birdDS_Long, aes(x=birdDS_Long$measurement, y = boneAlone, fill = measurementType)) +
geom_density_ridges2(scale = 1) +
theme_minimal(base_size = 14) + theme(axis.text.y = element_text(vjust = 0)) +
scale_x_continuous(expand = c(0.01, 0)) +
coord_cartesian(xlim = c(0, 200)) +
scale_y_discrete(expand = c(0.01, 0)) +
facet_grid(.~birdType)
ggplot(data = birdDS_Long, aes(x=birdDS_Long$measurement, y = boneAlone, fill = measurementType)) +
geom_density_ridges2(scale = 1, alpha=0.6) +
theme_minimal(base_size = 14) + theme(axis.text.y = element_text(vjust = 0)) +
scale_x_continuous(expand = c(0.01, 0)) +
coord_cartesian(xlim = c(0, 200)) +
scale_y_discrete(expand = c(0.01, 0)) +
facet_grid(.~birdType) +
theme_ridges() +
scale_fill_brewer(palette = 'Set1')
df() –> Shiny will know looking for a reactive element
ggplot(data = birdDS_Long, aes(x=birdDS_Long$measurement, y = boneAlone, fill = measurementType)) +
geom_density_ridges2(scale = 1, alpha=0.6) +
theme_minimal(base_size = 14) +
theme(axis.text.y = element_text(vjust = 0)) +
scale_x_continuous(expand = c(0.01, 0)) +
coord_cartesian(xlim = c(0, 200)) +
scale_y_discrete(expand = c(0.01, 0)) +
facet_grid(.~birdType) +
theme_ridges() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) +
theme(legend.position="none") +
scale_fill_brewer(palette = 'Set1')
ggplot(data = birdDS_Long, aes(x=birdDS_Long$measurement, y = boneAlone, fill = birdType)) +
geom_density_ridges2(scale = 1, alpha=0.6) +
theme_minimal(base_size = 14) + theme(axis.text.y = element_text(vjust = 0)) +
scale_x_continuous(expand = c(0.01, 0)) +
coord_cartesian(xlim = c(0, 200)) +
scale_y_discrete(expand = c(0.01, 0)) +
facet_grid(.~measurementType) +
theme_ridges() +
scale_fill_brewer(palette = 'Set1')
birdsPlot <- ggplot(data = birdDS_Long,
aes(x=birdDS_Long$measurement,
y = birdType,
fill = measurementType))
birdsPlot <- birdsPlot + geom_density_ridges2(scale = 0.9, alpha=0.6, colour = 'white', size = 0.1) +
theme(axis.text.y = element_text(vjust = 0)) +
#theme_minimal(base_size = 14) +
scale_x_continuous(expand = c(0.01, 0)) +
coord_cartesian(xlim = c(0, 150)) +
scale_y_discrete(expand = c(0.01, 0)) +
facet_grid(.~boneAlone) +
theme(legend.title = element_blank()) +
theme(legend.position='none') +
scale_fill_brewer(palette = 'Set1')
birdsPlot <- birdsPlot + theme(panel.spacing=grid::unit(0.3,"lines"),
axis.text = element_text(size = rel(0.5)),
strip.text = element_text(face = "bold", size=11),
strip.text.x = element_text(margin = margin(.1, 0, .1, 0, "cm")),
strip.text.y = element_text(margin = margin(0, .1, 0, .1, "cm")))
birdsPlot + theme(panel.border = element_rect(fill = NA, colour = "grey30", size = 0.1))
ftp://cran.r-project.org/pub/R/web/packages/ggridges/ggridges.pdf
library(viridis)
birdsPlot <- ggplot(data = birdDS_Long,
aes(x=birdDS_Long$measurement,
y = birdType,
fill = 0.5 - abs(0.5-..ecdf..)))
birdsPlot <- birdsPlot + stat_density_ridges(geom = "density_ridges_gradient", calc_ecdf = TRUE) +
scale_fill_viridis(name = "Tail probability", direction = -1) +
theme(axis.text.y = element_text(vjust = 0)) +
theme_minimal(base_size = 14) +
scale_x_continuous(expand = c(0.01, 0)) +
coord_cartesian(xlim = c(0, 150)) +
scale_y_discrete(expand = c(0.01, 0)) +
facet_grid(.~bone) +
theme(legend.title = element_blank()) +
theme(legend.position='none')
scale_fill_brewer(palette = 'Set1')
<ggproto object: Class ScaleDiscrete, Scale>
aesthetics: fill
axis_order: function
break_info: function
break_positions: function
breaks: waiver
call: call
clone: function
dimension: function
drop: TRUE
expand: waiver
get_breaks: function
get_breaks_minor: function
get_labels: function
get_limits: function
guide: legend
is_discrete: function
is_empty: function
labels: waiver
limits: NULL
make_sec_title: function
make_title: function
map: function
map_df: function
n.breaks.cache: NULL
na.translate: TRUE
na.value: NA
name: waiver
palette: function
palette.cache: NULL
position: left
range: <ggproto object: Class RangeDiscrete, Range>
range: NULL
reset: function
train: function
super: <ggproto object: Class RangeDiscrete, Range>
reset: function
scale_name: brewer
train: function
train_df: function
transform: function
transform_df: function
super: <ggproto object: Class ScaleDiscrete, Scale>
birdsPlot <- birdsPlot + theme(panel.spacing=grid::unit(0.3,"lines"),
axis.text = element_text(size = rel(0.5)),
strip.text = element_text(face = "bold", size=11),
strip.text.x = element_text(margin = margin(.1, 0, .1, 0, "cm")),
strip.text.y = element_text(margin = margin(0, .1, 0, .1, "cm")))
birdsPlot + theme(panel.border = element_rect(fill = NA, colour = "grey30", size = 0.1))
Acknowledgements This dataset is provided by Dr. D. Liu of Beijing Museum of Natural History.